package cn.rkylin.oms.aftersale.sysrefund.vo;

import java.util.Date;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;

import cn.rkylin.oms.aftersale.sysrefund.domain.SysRefund;
import cn.rkylin.oms.aftersale.sysrefund.domain.SysRefundSku;
import cn.rkylin.oms.aftersale.sysreturn.domain.SysReturnSku;
import cn.rkylin.oms.aftersale.sysreturn.vo.SysReturnVO;
import cn.rkylin.oms.common.consts.ECRefundStatusConsts;
import cn.rkylin.oms.common.consts.SysRefundStatusConsts;
import cn.rkylin.oms.common.consts.YesNoConst;
import cn.rkylin.oms.order.domain.OrderSku;

/**
 * 类名:SysRefundVO <br/>
 * 作用: 系统退款单值类. <br/>
 * 创建原因: 系统退款单值类. <br/>
 * 创建时间: 2017年9月22日 下午5:06:58 <br/>
 * 
 * @author zhanghao
 * @version v1.0
 */
public class SysRefundVO extends SysRefund {
    /**
     * 构造器：SysRefundVO.
     *
     */
    public SysRefundVO() {

    }

    /**
     * serialVersionUID:序列化ID.
     */
    private static final long serialVersionUID = -6298961922855686958L;

    private static final String STATUS_REFUNDSHOW = "<span class=\"fa fa-chevron-down\"></span>";

    // 按钮 开始
    private static final String OPERATION_BTN_EDIT = "<button onclick=\"sysRefundList.operationEdit(this)\" refundId=\"%s\" type=\"button\" class=\"btn btn-info btn-xs\" pepid=\"sysrefundEdit\"><i class=\"fa fa-edit\"></i>&nbsp;修改</button>";
    private static final String OPERATION_BTN_DELETE = "<button onclick=\"sysRefundList.operationDelete(this)\" refundId=\"%s\" type=\"button\" class=\"btn btn-danger btn-xs sysrefundDelete\" pepid=\"sysrefundDelete\"><i class=\"fa fa-trash-o\"></i>&nbsp;删除</button>";

    private static final String OPERATION_BTN_EDIT_DISABLED = "<button refundId=\"%s\" type=\"button\" class=\"btn btn-disable btn-xs\" disabled><i class=\"fa fa-edit\"></i>&nbsp;修改</button>";
    private static final String OPERATION_BTN_DELETE_DISABLED = "<button refundId=\"%s\" type=\"button\" class=\"btn btn-disable btn-xs\" disabled><i class=\"fa fa-trash-o\"></i>&nbsp;删除</button>";

    private static final String OPERATION_BTN_AUTHEN = "<button onclick=\"sysRefundList.authen(this)\" refundId=\"%s\" type=\"button\" class=\"btn btn-info btn-xs \"  pepid=\"sysrefundAuthen\"><i class=\"fa fa-check\"></i>&nbsp;审核</button>";
    private static final String OPERATION_BTN_CANCEL_AUTHEN = "<button onclick=\"sysRefundList.cancelAuthen(this)\" refundId=\"%s\" type=\"button\" class=\"btn btn-danger btn-xs \"  pepid=\"sysrefundCancelAuthen\"><i class=\"fa fa-times\"></i>&nbsp;取消审核</button>";
    private static final String OPERATION_BTN_FORCE_AUTHEN = "<button onclick=\"sysRefundList.forceAuthen(this)\" refundId=\"%s\" type=\"button\" class=\"btn btn-info btn-xs \"  pepid=\"sysrefundForceAuthen\"><i class=\"fa fa-check\"></i>&nbsp;强制审核</button>";

    private static final String OPERATION_BTN_REFUND = "<button onclick=\"sysRefundList.refund(this)\" refundId=\"%s\" type=\"button\" class=\"btn btn-success btn-xs \"  pepid=\"sysrefundRefund\"><i class=\"fa fa-cny\"></i>&nbsp;退款</button>";
    private static final String OPERATION_BTN_REFUND_DISABLED = "<button refundId=\"%s\" type=\"button\" class=\"btn btn-disabled btn-xs\" disabled><i class=\"fa fa-cny\"></i>&nbsp;退款</button>";
    // 按钮 结束

    /**
     * sysRefundSkuList:系统退款单对应的退款商品详情列表.
     */
    private List<SysRefundSku> sysRefundSkuList;

    /**
     * sysReturnSkuList4Detail:为系统退款单详情页的退入信息准备的退款商品列表，该商品列表满足：<br/>
     * 
     * 1. 属于退款单商品;2. 在退货单中出现；3. 并且包含：3.1. 退货单信息；3.2. 退货单商品信息
     * 
     * 4. 不属于该退款单,但是属于该退款单包含的退货单的商品，不出现在列表中。
     *
     */
    private List<SysReturnSku> sysReturnSkuList4Detail;

    public List<SysReturnSku> getSysReturnSkuList4Detail() {
        return sysReturnSkuList4Detail;
    }

    public void setSysReturnSkuList4Detail(List<SysReturnSku> sysReturnSkuList4Detail) {
        this.sysReturnSkuList4Detail = sysReturnSkuList4Detail;
    }

    /**
     * sysRefundGoodsList:本平台退款单对应的系统商品详情列表.
     */
    private List<OrderSku> orderSkuList;

    public List<OrderSku> getOrderSkuList() {
        return orderSkuList;
    }

    public void setOrderSkuList(List<OrderSku> orderSkuList) {
        this.orderSkuList = orderSkuList;
    }

    /**
     * sysReturnVO:相关的退货单信息.
     */
    private List<SysReturnVO> sysReturnVOList;

    public List<SysReturnVO> getSysReturnVOList() {
        return sysReturnVOList;
    }

    public void setSysReturnVOList(List<SysReturnVO> sysReturnVOList) {
        this.sysReturnVOList = sysReturnVOList;
    }

    /**
     * searchCondition:快速查询条件.
     */
    private String quickSearch;
    /**
     * orderBy:排序规则.
     */
    private String orderBy;

    public List<SysRefundSku> getSysRefundSkuList() {
        return sysRefundSkuList;
    }

    public void setSysRefundSkuList(List<SysRefundSku> sysRefundSkuList) {
        this.sysRefundSkuList = sysRefundSkuList;
    }

    public String getQuickSearch() {
        return quickSearch;
    }

    public void setQuickSearch(String quickSearch) {
        this.quickSearch = quickSearch;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    /**
     * returnDifference:退货差异.
     */
    private String returnDiff;
    /**
     * refundSourceOrderCode:来源单号.
     */
    private String refundSourceOrderCode;

    /**
     * consMobile:收货人手机号
     */
    private String consMobile;

    /**
     * paidDate:付款日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date paidDate;

    /**
     * refundSource:来源.
     */
    private String refundSource;

    /**
     * orderStatus：订单状态
     */
    private String orderStatus;

    public String getReturnDiff() {
        return returnDiff;
    }

    public void setReturnDiff(String returnDiff) {
        this.returnDiff = returnDiff;
    }

    public String getRefundSourceOrderCode() {
        return refundSourceOrderCode;
    }

    public void setRefundSourceOrderCode(String refundSourceOrderCode) {
        this.refundSourceOrderCode = refundSourceOrderCode;
    }

    public String getConsMobile() {
        return consMobile;
    }

    public void setConsMobile(String consMobile) {
        this.consMobile = consMobile;
    }

    public Date getPaidDate() {
        return paidDate;
    }

    public void setPaidDate(Date paidDate) {
        this.paidDate = paidDate;
    }

    public String getRefundSource() {
        return refundSource;
    }

    public void setRefundSource(String refundSource) {
        this.refundSource = refundSource;
    }

    public String getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(String orderStatus) {
        this.orderStatus = orderStatus;
    }

    private String operation;

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        StringBuffer opButton = new StringBuffer();
        if (SysRefundStatusConsts.REGISTER.equalsIgnoreCase(getRefundStatus())
                && (ECRefundStatusConsts.EC_WAIT_SELLER_AGREE.equalsIgnoreCase(getEcRefundStatus())
                        || ECRefundStatusConsts.EC_WAIT_SELLER_CONFIRM_GOODS.equalsIgnoreCase(getEcRefundStatus()))) {
            // 待审核：可以执行审核和强制审核，对手动创建的还可以执行删除和修改

            opButton.append(String.format(OPERATION_BTN_AUTHEN, getRefundId()));
            opButton.append("&nbsp;");
            opButton.append(String.format(OPERATION_BTN_FORCE_AUTHEN, getRefundId()));
            opButton.append("&nbsp;");
            if (YesNoConst.NO.equalsIgnoreCase(getIsAutoCreate())) {
                opButton.append(String.format(OPERATION_BTN_EDIT, getRefundId()));
                opButton.append("&nbsp;");
                opButton.append(String.format(OPERATION_BTN_DELETE, getRefundId()));
                opButton.append("&nbsp;");
            } else {
				 opButton.append(String.format(OPERATION_BTN_EDIT_DISABLED, getRefundId()));
				 opButton.append("&nbsp;");
				 opButton.append(String.format(OPERATION_BTN_DELETE_DISABLED, getRefundId()));
				 opButton.append("&nbsp;");
            }
        } else if (SysRefundStatusConsts.AUTHENTICATED.equalsIgnoreCase(getRefundStatus())
                && (ECRefundStatusConsts.EC_WAIT_SELLER_AGREE.equalsIgnoreCase(getEcRefundStatus())
                        || ECRefundStatusConsts.EC_WAIT_SELLER_CONFIRM_GOODS.equalsIgnoreCase(getEcRefundStatus()))) {
            // 待退款：可以执行取消审核
            opButton.append(String.format(OPERATION_BTN_CANCEL_AUTHEN, getRefundId()));
            opButton.append("&nbsp;");
            // 对手动创建的线下的还可以执行退款
            if (YesNoConst.NO.equals(getIsAutoCreate())
            // && OnOffLineConsts.OFFLINE.equals(getRefundChannel()) //
            // 变更——手动创建的退款单无论线上线下都可以退款
            ) {
                opButton.append(String.format(OPERATION_BTN_REFUND, getRefundId()));
                opButton.append("&nbsp;");
            } else {
            	opButton.append(String.format(OPERATION_BTN_REFUND_DISABLED, getRefundId()));
            	opButton.append("&nbsp;");
            }
        }
        this.operation = opButton.toString();
    }

    /**
     * ecTradeCode:平台交易号.
     */
    private String ecTradeCode;

    public String getEcTradeCode() {
        return ecTradeCode;
    }

    public void setEcTradeCode(String ecTradeCode) {
        this.ecTradeCode = ecTradeCode;
    }

    private String ecOrderStatus; // 交易状态(订单)

    public String getEcOrderStatus() {
        return ecOrderStatus;
    }

    public void setEcOrderStatus(String ecOrderStatus) {
        this.ecOrderStatus = ecOrderStatus;
    }

    /**
     * onOffLine:线上／线下.
     */
    private String onOffLine;

    public String getOnOffLine() {
        // TODO：线上还是线下
        onOffLine = "线上";
        return onOffLine;
    }

    public void setOnOffLine(String onOffLine) {
        this.onOffLine = onOffLine;
    }

    /**
     * sonShow:显示详情按钮.
     */
    private String sonShow;

    public String getSonShow() {
        return STATUS_REFUNDSHOW;
    }

    public void setSonShow(String sonShow) {
        this.sonShow = sonShow;
    }

    /**
     * queryStatus:界面查询状态 已申请退货： 待买家操作： 待审核： 待退款： 已完成： 已废弃：
     */
    private String queryStatus;

    public String getQueryStatus() {
        return queryStatus;
    }

    public void setQueryStatus(String queryStatus) {
        this.queryStatus = queryStatus;
    }

    /**
     * queryECStatus:平台退款单查询条件列表.
     */
    public List queryECStatus;

    /**
     * queryStatus:系统退款单查询条件列表.
     */
    public List querySysStatus;

    public List getQueryECStatus() {
        return queryECStatus;
    }

    public void setQueryECStatus(List queryECStatus) {
        this.queryECStatus = queryECStatus;
    }

    public List getQuerySysStatus() {
        return querySysStatus;
    }

    public void setQuerySysStatus(List querySysStatus) {
        this.querySysStatus = querySysStatus;
    }

    /*
     * 高级查询相关的条件
     */
    /**
     * queryOrderCode:订单号.
     */
    private String queryOrderCode;
    /**
     * queryShopName:店铺名称.
     */
    private String queryShopName;
    /**
     * querySource:订单来源.
     */
    private String querySource;
    /**
     * queryDateType:日期类型.
     */
    private String queryDateType;
    /**
     * queryDateStart:开始日期.
     */
    private Date queryDateStart;
    /**
     * queryDateEnd:结束日期.
     */
    private Date queryDateEnd;
    /**
     * queryEcItemCode:平台商品编号.
     */
    private String queryEcItemCode;
    /**
     * queryEcSkuCode:规格平台编号.
     */
    private String queryEcSkuCode;
    /**
     * querySkuCode:商家规格编号.
     */
    private String querySkuCode;

    public String getQueryOrderCode() {
        return queryOrderCode;
    }

    public void setQueryOrderCode(String queryOrderCode) {
        this.queryOrderCode = queryOrderCode;
    }

    public String getQueryShopName() {
        return queryShopName;
    }

    public void setQueryShopName(String queryShopName) {
        this.queryShopName = queryShopName;
    }

    public String getQuerySource() {
        return querySource;
    }

    public void setQuerySource(String querySource) {
        this.querySource = querySource;
    }

    public String getQueryDateType() {
        return queryDateType;
    }

    public void setQueryDateType(String queryDateType) {
        this.queryDateType = queryDateType;
    }

    public String getQueryEcItemCode() {
        return queryEcItemCode;
    }

    public void setQueryEcItemCode(String queryEcItemCode) {
        this.queryEcItemCode = queryEcItemCode;
    }

    public String getQueryEcSkuCode() {
        return queryEcSkuCode;
    }

    public void setQueryEcSkuCode(String queryEcSkuCode) {
        this.queryEcSkuCode = queryEcSkuCode;
    }

    public String getQuerySkuCode() {
        return querySkuCode;
    }

    public void setQuerySkuCode(String querySkuCode) {
        this.querySkuCode = querySkuCode;
    }

    public Date getQueryDateStart() {
        return queryDateStart;
    }

    public void setQueryDateStart(Date queryDateStart) {
        this.queryDateStart = queryDateStart;
    }

    public Date getQueryDateEnd() {
        return queryDateEnd;
    }

    public void setQueryDateEnd(Date queryDateEnd) {
        this.queryDateEnd = queryDateEnd;
    }

    /**
     * queryStatus:系统退款单查询条件列表.
     */
    public List primariyKeyList;

    public List getPrimariyKeyList() {
        return primariyKeyList;
    }

    public void setPrimariyKeyList(List primariyKeyList) {
        this.primariyKeyList = primariyKeyList;
    }

    /*
     * 列表和详情展现相关字段
     */
    // 货物状态中文
    private String goodsStatusString;

    public String getGoodsStatusString() {
        return goodsStatusString;
    }

    public void setGoodsStatusString(String goodsStatusString) {
        String status = getGoodStus();
        switch (status) {
        case "BUYER_NOT_RECEIVED": {
            goodsStatusString = "买家未收到货";
            break;
        }
        case "BUYER_RECEIVED": {
            goodsStatusString = "买家已收到货";
            break;
        }
        case "BUYER_RETURNED_GOODS": {
            goodsStatusString = "买家已退货";
            break;
        }
        default: {
            goodsStatusString = "-";
            break;
        }
        }
        this.goodsStatusString = goodsStatusString;
    }

    // 平台退款状态中文
    private String ecRefundStatusString;

    public String getEcRefundStatusString() {
        return ecRefundStatusString;
    }

    public void setEcRefundStatusString(String ecRefundStatusString) {
        if (YesNoConst.YES.equals(getIsAutoCreate())) {
            String status = getEcRefundStatus().toUpperCase();
            switch (status) {
            case "EC_CLOSED": {
                ecRefundStatusString = "退款关闭";
                break;
            }
            case "EC_SELLER_REFUSE_BUYER": {
                ecRefundStatusString = "卖家拒绝退款";
                break;
            }
            case "EC_SUCCESS": {
                ecRefundStatusString = "退款成功";
                break;
            }
            case "EC_WAIT_BUYER_RETURN_GOODS": {
                ecRefundStatusString = "卖家已经同意退款，等待买家退货";
                break;
            }
            case "EC_WAIT_SELLER_AGREE": {
                ecRefundStatusString = "买家已经申请退款，等待卖家同意";
                break;
            }
            case "EC_WAIT_SELLER_CONFIRM_GOODS": {
                ecRefundStatusString = "买家已经退货，等待卖家确认收货";
                break;
            }
            default: {
                ecRefundStatusString = "-";
                break;
            }
            }
        } else {
            ecRefundStatusString = "";
        }

        this.ecRefundStatusString = ecRefundStatusString;
    }
}
